Skip to content

Use dumpsys deviceidle get screen in CMD_SCREEN_ON - #369

Open
tgrushka wants to merge 1 commit into
JeffLIrion:masterfrom
dra11y:avoid-early-exit-grep-on-dumpsys
Open

Use dumpsys deviceidle get screen in CMD_SCREEN_ON#369
tgrushka wants to merge 1 commit into
JeffLIrion:masterfrom
dra11y:avoid-early-exit-grep-on-dumpsys

Conversation

@tgrushka

@tgrushka tgrushka commented Aug 2, 2026

Copy link
Copy Markdown

This PR:

On Android 14, both dumpsys power greps no longer match. It prints Display Power: com.android.server.power.PowerManagerService$1@a8a75e6 with no state= field, and mScreenOn=true is gone. So each poll, every 10 seconds, falls back to dumpsys display, a much more expensive call.

EDIT: Tested on LineageOS 21 (Android 14, SDK 34), x86_64 Android TV.

Because grep -q terminates on first match, the pipe is broken, resulting in a stack trace every 10 seconds that looks like:

W FastPrintWriter: Write failure
W FastPrintWriter: java.io.IOException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:651)
W FastPrintWriter: 	at java.io.FileOutputStream.write(FileOutputStream.java:432)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:355)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:378)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:413)
W FastPrintWriter: 	at android.os.Binder.dump(Binder.java:1158)
W FastPrintWriter: 	at android.os.Binder.onTransact(Binder.java:1022)
W FastPrintWriter: Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:646)
W FastPrintWriter: 	... 9 more

This PR fixes the issue:

@tgrushka
tgrushka force-pushed the avoid-early-exit-grep-on-dumpsys branch 2 times, most recently from de9e1ce to 45f0456 Compare August 2, 2026 22:02
This PR:
- fixes a broken pipe like in JeffLIrion#351, but from `grep -q` instead of `grep -m 1`
- uses a much more efficient call to get screen state

On Android 14, both `dumpsys power` greps no longer match. It prints
`Display Power: com.android.server.power.PowerManagerService$1@a8a75e6` with
no `state=` field, and `mScreenOn=true` is gone. So each poll, every 10
seconds, falls back to `dumpsys display`, a much more expensive call.

Because `grep -q` terminates on first match, the pipe is broken, resulting in
a stack trace every 10 seconds that looks like:

```
W FastPrintWriter: Write failure
W FastPrintWriter: java.io.IOException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:651)
W FastPrintWriter: 	at java.io.FileOutputStream.write(FileOutputStream.java:432)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:355)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:378)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:413)
W FastPrintWriter: 	at android.os.Binder.dump(Binder.java:1158)
W FastPrintWriter: 	at android.os.Binder.onTransact(Binder.java:1022)
W FastPrintWriter: Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:646)
W FastPrintWriter: 	... 9 more
```

This PR fixes the issue:
- uses `dumpsys deviceidle get screen` to check screen state, which is cheap
  and has been available since Android 7
- removes `-q` so grep will not stop on first match and cause broken pipe
@tgrushka
tgrushka force-pushed the avoid-early-exit-grep-on-dumpsys branch from 45f0456 to 21b2836 Compare August 2, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant